#include <stdio.h>
#include <time.h>
#include <math.h>

#define MAXN 10
#define MAXK 1e6
double f1 (int n, double a[], double x) {
    double p = a[0];
    for (int i = 1; i < n; ++i) {
        p += (a[i] * pow(x, i));
    }
    return p;
}

double f2 (int n, double a[], double x) {
    double p = a[n];
    for (int i = n; i > 0; --i) {
        p = a[i-1] + p * x;
    }
    return p;
}

int main(int argc, char *argv[]) {
    double start, end;
    double a[MAXN];
    for (int i = 0; i < MAXN; ++i) {
        a[i] = i;
    }

    start = clock();
    for (int i = 0; i < MAXK; ++i) {
        f1(MAXN-1, a, 1.1);
    }
    end = clock();
    printf("tick1 = %.6f\n", (double)(end - start));
    printf("f1: %.6f\n", (double)((end - start) / CLOCKS_PER_SEC));

    start = clock();
    for (int i = 0; i < MAXK; ++i) {
        f2(MAXN-1, a, 1.1);
    }
    end = clock();
    printf("tick2 = %.6f\n", (double)(end - start));
    printf("f1: %.6f\n", (double)((end - start) / CLOCKS_PER_SEC));
    return 0;
}